package datasource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by Administrator on 2017/9/14.
 */
public class C3P0Utils {

    public  static ComboPooledDataSource cpds = null;
    static {
        //只需要创建一次? static 代码块: 只加载一次
        cpds = new ComboPooledDataSource();
        //设置与数据库的关联
        try{
            cpds.setDriverClass("com.mysql.jdbc,Driver");
            cpds.setJdbcUrl("jdbc:mysql://localhost:3307/jdbc");
            cpds.setUser("root");
            cpds.setPassword("123456");

            cpds.setInitialPoolSize(5);
            cpds.setMaxPoolSize(15);
        }catch (PropertyVetoException e){
            e.printStackTrace();
        }
    }
    public static Connection getCinnection() throws SQLException{
        return cpds.getConnection();
    }
}
